package com.propertyportal.propertylistfragment;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import android.os.AsyncTask;
import android.widget.Toast;

public class DeleteProperty extends AsyncTask<Integer, Void, Void> {
	//private SherlockFragmentActivity fa;
	String outputs="Unable to Delete!";
	//private ProgressDialog dialog = new ProgressDialog(PropertyList.fa);

	protected void onPreExecute() {
		//dialog.setMessage("Loading...");
		//dialog.show();
	}

	@Override
	protected Void doInBackground(Integer... id) {
		
		String urla = "http://192.168.2.38:8080/STTHERESEREALTYWS/webresources/com.propertyportal.entities.property/";
		try {
			URL url = new URL(urla + id[0]);
			HttpURLConnection conn = (HttpURLConnection) url.openConnection();
			conn.setRequestMethod("DELETE");
			conn.setRequestProperty("Content-Type", "application/json");
			if (conn.getResponseCode() != 200) {
				throw new RuntimeException("Failed : HTTP error code : "
						+ conn.getResponseCode());
			} else {
				System.out.print("Succes");
			}
			BufferedReader br = new BufferedReader(new InputStreamReader(
					(conn.getInputStream())));

			String output;
			System.out.println("Output from Server .... \n");
			while ((output = br.readLine()) != null) {
				//System.out.println(output);
				outputs=output;
			}
			conn.disconnect();
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	protected void onPostExecute(Void result) {
		/*if (this.dialog != null) {
			this.dialog.dismiss();
		}*/
	 Toast.makeText(PropertyList.fa, outputs,Toast.LENGTH_LONG).show();
		// Toast.LENGTH_LONG).show();
	 PropertyList pl = new PropertyList();
	 pl.callUpdate();
	 
	 
	}

}
